package com.oschina.basic.io;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.junit.Test;

public class MyFileIOTest {

	@Test
	public void testWrite() throws IOException {
		MyFileIO writer = new MyFileIO("f:\\test.txt", "UTF-8");
		writer.write("f:\\test.txt", "this is a 发大水");
	}

	@Test
	public void testRead() throws IOException {
		MyFileIO reader = new MyFileIO("f:\\test.txt", "UTF-8");
		String result = reader.read("f:\\test.txt");
		System.out.println(result);
		assertEquals(result.trim(), "this is a 发大水");
	}

	@Test
	public void testMerge() throws IOException {
		MyFileIO reader = new MyFileIO("f:\\test.txt", "UTF-8");
		StringBuffer wA = new StringBuffer();
		for (int m = 0; m < 50; m++) {
			wA.append(m + "A\n");
		}
		wA.deleteCharAt(wA.length() - 1);
		StringBuffer wB = new StringBuffer();
		for (int i = 0; i < 60; i++) {
			wB.append(i + "B\n");
		}
		wB.deleteCharAt(wB.length() - 1);

		reader.write("f:\\testA.txt", wA.toString());
		reader.write("f:\\testB.txt", wB.toString());


		reader.merge("f:\\testA.txt", "f:\\testB.txt", "f:\\testC.txt");
	}

}

